import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-05-14
 * Time: 14:02
 */
public class TestDemo {
    public boolean isSubsequence (String S, String T) {
        // write code here
        int lenS = S.length();
        int lenT = T.length();
        int i = 0;//遍历S
        int j = 0;//遍历T
        while (i < lenS && j < lenT) {
            if (S.charAt(i) == T.charAt(j)) {
                i++;
                j++;
            } else {
                j++;
            }
        }
        return i == lenS;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Stack<Character> stack = new Stack<>();
        while (scanner.hasNextLine()) {
            String str = scanner.nextLine();
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                if (stack.isEmpty() || ch != stack.peek()) {
                    stack.push(ch);
                }
            }
        }
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String str = scanner.nextLine();
            Stack<Character> stack = new Stack<>();
            List<Character> list = new ArrayList<>();
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                if (stack.isEmpty() || ch != stack.peek()) {
                    stack.push(ch);
                } else {
                    stack.pop();
                }
            }
            //此时我们拿到的序列就是我们所需要的 但是说逆序的 所以我们需要逆序一下我们栈中的顺序
            if (stack.isEmpty()) {
                System.out.println("0");
            } else {
                while (!stack.isEmpty()) {
                    list.add(stack.pop());
                }
            }
            Collections.reverse(list);
            for (Character character : list) {
                System.out.print(character);
            }
        }
    }
    public static void main2(String[] args) {
        Stack<Character> stack = new Stack<>();
        System.out.println(stack.isEmpty());
        stack.push('a');
        stack.push('b');
        System.out.println(stack.isEmpty());
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {// 注意while 处理多个 case
            String str = in.nextLine();
            Stack<Character> stack = new Stack<>();
            List<Character> list = new ArrayList<>();
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                if (stack.isEmpty() || ch != stack.peek()) {//两者只要一真则为真
                    stack.push(ch);
                } else {
                    stack.pop();
                }
            }
            //此时栈当中的数据 就是我需要的数据 但是此时 是逆序的
            if (stack.isEmpty()) {
                System.out.println("0");
            } else {
                while (!stack.isEmpty()) {
                    list.add(stack.pop());
                }
                Collections.reverse(list);
//                for (Character character : list) {
//                    System.out.print(character);
//                }
//                System.out.println();
                for (int i = 0; i < list.size(); i++) {
                    System.out.print(list.get(i));
                }
            }
        }
    }

}
